<!-- 我的博客数据, 展示发布博客的数量, 以及关注粉丝数量 -->
<template>
  <div class="user-manage" id="top">
    <!-- 头部 -->
    <div class="manage-content-header">
      <h1>用户管理</h1>
      <small class="">博客数据</small>
      <div>
        <ul class="content-header-nav">
          <li>
            后台管理
            <i class="el-icon-arrow-right"></i>
          </li>
          <li>
            用户管理
            <i class="el-icon-arrow-right"></i>
          </li>
          <li>我的博客数据</li>
        </ul>
      </div>
    </div>
    <!-- 内容 -->
    <div class="user-data-container">
      <!-- 用户信息展示, 显示用户头像,关注, 粉丝用户名 -->

      <!-- 返回我的主页 -->
      <div class="go-my-homepage" v-if="goBack">
        <el-button
          type="info"
          class="el-icon-back"
          round
          @click="goMyPage"
        ></el-button>
      </div>

      <div class="user-msg-show">
        <!-- 头像 -->
        <div class="avatar" id="user-avatar">
          <img :src="userBlogInfo.avatar" alt="" />
        </div>
        <div class="user-msg">
          <!-- 用户名 -->
          <span class="username">
            {{ userBlogInfo.username }}
          </span>
          <!-- 关注/粉丝 -->
          <div class="follow-box">
            <!-- 关注 -->
            <span class="follower"
              >粉丝: {{ userBlogInfo.followerCount }} /
            </span>
            <!-- 粉丝 -->
            <span class="follow">关注: {{ userBlogInfo.followCount }}</span>
          </div>
        </div>
      </div>

      <!-- 博客数据统计, 显示入驻时间, 发布博客数据, 评论回复数据 -->
      <div class="user-data-box">
        <h1>数据统计</h1>
        <div class="card">
          <el-card :body-style="{ padding: '0px' }">
            <div class="card-icon">
              <div class="icon-box el-icon-user-solid"></div>
            </div>
            <div style="padding-top: 40px; color: #9a9ca1">
              <span>入驻时间</span>
            </div>
            <div class="content">{{ userBlogInfo.enterTime }}</div>
          </el-card>
          <el-card :body-style="{ padding: '0px' }">
            <div class="card-icon">
              <div class="icon-box el-icon-reading"></div>
            </div>
            <div style="padding-top: 40px; color: #9a9ca1">
              <span>发布文章</span>
            </div>
            <div class="content">{{ userBlogInfo.sendBlogCount }} 篇</div>
          </el-card>
          <el-card :body-style="{ padding: '0px' }">
            <div class="card-icon">
              <div class="icon-box el-icon-s-comment"></div>
            </div>
            <div style="padding-top: 40px; color: #9a9ca1">
              <span>评论回复</span>
            </div>
            <div class="content">{{ userBlogInfo.commentCount }} 次</div>
          </el-card>
        </div>
      </div>

      <!-- 关注的用户 -->
      <div class="user-data-box">
        <h1>Ta关注的用户</h1>
        <div class="follow-card">
          <el-card
            :body-style="{ padding: '0px' }"
            v-for="(user, index) in userBlogInfo.followList"
            :key="index"
          >
            <div class="card-user-msg">
              <div style="display: flex">
                <div class="user-avatar">
                  <img :src="user.avatar" alt="" />
                </div>
                <span class="username">{{ user.username }}</span>
              </div>

              <div class="follow-user-blog-msg">
                <div class="msg-item">
                  发布了 {{ user.sendBlogCount }} 篇文章
                </div>
                <div class="msg-item">
                  拥有了 {{ user.followerCount }} 个粉丝
                </div>
                <div class="msg-item">
                  评论回复了 {{ user.commentCount }} 次
                </div>
                <div class="homepage">
                  <button class="homepage-btn" @click="goFollowUserPage(user)">
                    前往主页
                  </button>
                </div>
              </div>
            </div>
          </el-card>
          <div class="no-follow" v-if="userBlogInfo.followList == null">
            Ta还没有关注的用户哦!
          </div>
        </div>
      </div>

      <!-- 粉丝 -->
      <div class="user-data-box">
        <h1>Ta的粉丝</h1>
        <div class="follow-card">
          <el-card
            :body-style="{ padding: '0px' }"
            v-for="(user, index) in userBlogInfo.followerList"
            :key="index"
          >
            <div class="card-user-msg">
              <div style="display: flex">
                <div class="user-avatar">
                  <img :src="user.avatar" alt="" />
                </div>
                <span class="username">{{ user.username }}</span>
              </div>

              <div class="follow-user-blog-msg">
                <div class="msg-item">
                  发布了 {{ user.sendBlogCount }} 篇文章
                </div>
                <div class="msg-item">
                  拥有了 {{ user.followerCount }} 个粉丝
                </div>
                <div class="msg-item">
                  评论回复了 {{ user.commentCount }} 次
                </div>
                <div class="homepage">
                  <button class="homepage-btn" @click="goFollowUserPage(user)">
                    前往主页
                  </button>
                </div>
              </div>
            </div>
          </el-card>
          <div class="no-follow" v-if="userBlogInfo.followerList == null">
            Ta还没有粉丝哦!
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import UserApiRequest from "@/api/UserApiRequest";
const userApiRequest = new UserApiRequest();
export default {
  data() {
    return {
      userMsgForm: {
        username: "",
        avatarUrl: "",
      },
      userBlogInfo: [],
      goBack: false,
    };
  },
  methods: {
    goFollowUserPage(userInfo) {
      let data = {
        userId: userInfo.userId,
      };
      userApiRequest.getUserBlogInfo(data).then((res) => {
        this.userBlogInfo = res.data;
      });
      this.$nextTick(() => {
        let ele = document.getElementById("top");
        ele.scrollIntoView({ behavior: "smooth" });
      });

      this.goBack = true;
    },
    goMyPage() {
      this.goBack = false;
      let data = {
        userId: this.$store.state.userInfo.uid,
      };
      userApiRequest.getUserBlogInfo(data).then((res) => {
        this.userBlogInfo = res.data;
      });
    },
  },
  mounted() {
    // 加载组件的时候当前主页用户的信息
    this.userMsgForm.avatarUrl = this.$store.state.userInfo.loginUrlAvatar;
    this.userMsgForm.username = this.$store.state.userInfo.username;

    let data = {
      userId: this.$store.state.userInfo.uid,
    };
    userApiRequest.getUserBlogInfo(data).then((res) => {
      this.userBlogInfo = res.data;
      if (res.code === -404) {
        this.$message.error("用户数据异常");
        return;
      }
    });
  },
};
</script>

<style scoped lang="scss">
.user-manage {
  .manage-content-header {
    position: relative;
    padding: 15px 15px 0 15px;
    h1 {
      font-size: 24px;
      font-weight: 400;
    }
    small {
      margin-left: 5px;
      font-size: 15px;
    }
    h1,
    small,
    ul {
      display: inline-block;
    }
    .content-header-nav {
      position: absolute;
      top: 30px;
      right: 15px;
      float: right;
      li:first-child {
        font-weight: 700;
        color: #303133;
      }
      li {
        color: #606266;
        float: left;
        font-size: 12px;
      }
    }
  }
}
.user-data-container {
  position: relative;
  border-radius: 3px;
  background: #fff;
  border-top: 3px solid #3c8dbc;
  padding: 20px;
  margin-top: 20px;
  margin-bottom: 20px;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);

  .go-my-homepage {
    position: absolute;
    top: 30px;
    left: 35px;
  }
  .user-msg-show {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    .avatar img {
      width: 80px;
      height: 80px;
      border-radius: 50%;
    }
    .user-msg {
      text-align: center;
      margin-top: 15px;
      .username {
        font-weight: 700;
      }
      .follow-box {
        margin-top: 5px;
        font-size: 14px;
        color: #9a9ca1;
      }
    }
  }

  .user-data-box {
    padding-left: 20px;
    h1 {
      font-size: 24px;
    }
    .card {
      display: flex;
      flex-wrap: wrap;
      justify-content: center;
      margin-top: 30px;
      transition: all 0.5s; // 表示从 hover 进入普通状态时，0.5s 内完成变换
      box-shadow: 0 0 0 rgba(0, 0, 0, 0);
      .el-card {
        margin: 20px;
        padding: 20px;
        text-align: center;
        border-radius: 8px;
        .content {
          font-weight: 700;
          margin-top: 10px;
          margin-bottom: 20px;
        }

        &:hover {
          transition: all 0.2s; // 表示进入 hover 状态时，0.2s 内完成变换
          box-shadow: 12px 20px 5px rgba(0, 0, 0, 0.07),
            0px 10px 5px rgba(0, 0, 0, 0.06);
          transform: translateY(-10px);
          cursor: pointer;
        }
      }
      .card-icon {
        text-align: center;
        margin-right: 50px;
        margin-left: 50px;
        .icon-box {
          width: 65px;
          height: 65px;
          border-radius: 50%;
          text-align: center;
          line-height: 65px;
          font-size: 20px;
          background-color: skyblue;
        }
      }
    }
    .follow-card {
      display: flex;
      flex-wrap: wrap;
      justify-content: start;
      margin-top: 30px;
      transition: all 0.5s; // 表示从 hover 进入普通状态时，0.5s 内完成变换
      box-shadow: 0 0 0 rgba(0, 0, 0, 0);

      .el-card {
        padding: 20px;
        width: 200px;
        margin: 20px;
        background-color: #c1f1ff;
        border-radius: 6px;
      }
      .el-card:hover {
        transform: translateY(-10px);
        box-shadow: 12px 20px 5px rgba(0, 0, 0, 0.07),
          0px 10px 5px rgba(0, 0, 0, 0.06);
        cursor: pointer;
      }
      .card-user-msg {
        box-sizing: border-box;
        .user-avatar {
          img {
            width: 60px;
            height: 60px;
            border-radius: 50%;
          }
        }
        .username {
          font-weight: 700;
          font-family: Century Gothic, serif;
          margin-left: 10px;
          margin-top: 4px;
          color: #3d3d3d;
        }
        .follow-user-blog-msg {
          margin-top: 20px;
          .msg-item {
            margin: 5px 0;
          }

          .homepage {
            margin: 10px 0px;
            .homepage-btn {
              border-radius: 5px;
              color: #fff;
              padding: 5px;
              border: 1px solid #d1d2d3;
              background-color: rgb(140, 197, 255);
              cursor: pointer;

              &:hover {
                background-color: blue;
                transition: all 0.7s;
              }
            }
          }
        }
      }
      .no-follow {
        margin: auto;
        padding: 20px;
        font-weight: 700;
        color: #3d3d3d;
      }
    }
  }
}
::v-deep .el-form-item__content {
  width: 100%;
}
.el-form-item {
  display: flex;
  width: 100%;
}
</style>
